package repository

import (
	"blog/internal/model"
	"gorm.io/gorm"
)

type ArticleRepository struct {
	db *gorm.DB
}

func NewArticleRepository(db *gorm.DB) *ArticleRepository {
	return &ArticleRepository{db: db}
}

func (r *ArticleRepository) FindByID(id uint) (model.Article, error) {
	var article model.Article
	if err := r.db.First(&article, id).Error; err != nil {
		return model.Article{}, err
	}
	return article, nil
}

func (r *ArticleRepository) FindAll() ([]model.Article, error) {
	var articles []model.Article
	if err := r.db.Find(&articles).Error; err != nil {
		return articles, err
	}
	return articles, nil
}
